<?php

class AdminNewsIndexController extends AdminIndexController 
{
    public function prepare()
    {
        $page = Env::request('page', 1);
        
        $id = Env::get('id');
        $title = Env::get('title');
        $status = Env::get('status');
        
        if ($status == -1) {
            $status = null;
        }
        
        $filter = array();
        if ($id) {
            $filter['id'] = $id;
        }
        if ($title) {
            $filter['title'] = $title;
        }
        
        $order_field = Env::get('order_field', 'pubdate');
        $order_by = Env::get('order_by', 'DESC');
        
        $order = array(
            'field' => $order_field,
            'by' => $order_by
        );
        
        $NewsModel = new NewsModel();
        $news = $NewsModel->getList($page, NewsModel::ADMIN_NEWS_ON_PAGE, $status, $filter, $order);

        $Pager = new Pager($NewsModel->getTotalCount(), $page, NewsModel::ADMIN_NEWS_ON_PAGE);
        
        $this->view->assign('pager', $Pager);
        $this->view->assign('list', $news);
    }
}

?>